package logic

import (
	"8-dshop/api/internal/utils"
	"8-dshop/shoprpc/shoprpc"
	"context"

	"8-dshop/api/internal/svc"
	"8-dshop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
	return &ProductListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductListLogic) ProductList(req *types.ProductListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.ShopRpc.ProductList(l.ctx, &shoprpc.ProductListRequest{
		UserId: req.UserId,
	})
	if err != nil {
		return utils.ReturnResponse(err.Error(), 0, nil)
	}
	return utils.ReturnResponse("查询商品列表成功", 200, list)
}
